const DB = require('../../../utils/db')
const JwtUtil = require('../../../utils/jwt')
/**
 * GET
 * 获取申请的群列表
 * 自己申请别人的群聊
 */

module.exports = async (ctx) => {
  // 获取token
  let token = ctx.request.header.authorization
  let jwt = new JwtUtil(token)
  // 用token获取到userid
  let userid = jwt.verifyToken()
  // 我申请别人的群聊
  // 从user_group_apply中查询我（761916205@qq.com）申请的群聊，然后从group中查询群聊的具体信息（groupid,groupName,introduction,applyStatus）
  const applyList = await DB.query(
    `SELECT uga.groupid, g.groupName, g.introduction, uga.applyStatus from user_group_apply uga join \`group\` g on uga.groupid = g.groupid where uga.userid = '${userid}'`
  )
  console.log(
    `SELECT uga.groupid, g.groupName, g.introduction, uga.applyStatus from user_group_apply uga join \`group\` g on uga.groupid = g.groupid where uga.userid = '${userid}'`
  )
  //avatar userid username
  ctx.body = {
    code: 0,
    data: applyList,
  }
}
